home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / +ORC / Orc pac 6 / HOWTO61.TXT < prev    next >
Encoding:
Text File  |  2000-05-25  |  23.1 KB  |  458 lines

  1.                      HOW TO CRACK, by +ORC, A TUTORIAL
  2.  
  3. ---------------------------------------------------------------------------
  4.  
  5.                         Lesson 6.1: Funny tricks (1)
  6.  
  7. ---------------------------------------------------------------------------
  8.  
  9. LESSON 6 (1) - Funny tricks.  Xoring, Junking, Sliding
  10. EXERCISE 01: [LARRY in search of the King]
  11.      Before the next step let's resume what you have learned in
  12. the lessons 3-5, beginning with a very simple crack exercise
  13. (again, we'll use the protection scheme of a game, for the
  14. reasons explained in lesson 1): SEARCH FOR THE KING (Version
  15. 1.1.). This old "Larry" protection sequence, is a "paper
  16. protection" primitive. It's a very widespread (and therefore easy
  17. to find) program, and one of the first programs that instead of
  18. asking meaningful passwords (which offer us the possibility to
  19. immediately track them down in memory) asked for a random number
  20. that the good buyer could find on the manual, whereby the bad
  21. cracker could not. (Here you choose -with the mouse- one number
  22. out of 5 possible for a "gadget" choosen at random). I don't need
  23. any more to teach you how to find the relevant section of code
  24. (-> see lesson 3). Once you find the protection, this is what you
  25. get:
  26.  
  27. :protection_loop
  28.  :C922 8E0614A3       MOV     ES,[A314]
  29. ...
  30.  :C952 50 0E          PUSH    AX & CS
  31.  :C954 E81BFF         CALL    C872      <- call protection scheme
  32.  :C957 5B             POP     BX twice
  33.  :C959 8B76FA         MOV     SI,[BP-06] <- prepare store_room
  34.  :C95C D1E6           SHL     SI,1       <- final prepare
  35.  :C95E 8942FC         MOV     [BP+SI-04],AX  <- store AX
  36.  :C961 837EFA00       CMP     Word Ptr [BP-06],+00  <- good_guy?
  37.  :C965 75BB           JNZ     C922           <- loop, bad guy
  38.  :C967 8E0614A3       MOV     ES,[A314]
  39.  :C96B 26F606BE3501   TEST    Byte Ptr ES:[35BE],01  <- bad_guy?
  40.  :C971 74AF           JZ C922                <- loop, bad guy
  41.  :C973 8B46FC         MOV     AX,[BP-04]...  <- go on good guy
  42.  
  43. Let's see now the protection scheme called from :C954
  44.  :C872 55             PUSH    BP
  45. ...
  46.  :C8F7 90             NOP
  47.  :C8F8 0E             PUSH    CS
  48.  :C8F9 E87234         CALL    FD6E <- call user input
  49.  :C8FC 5B             POP     BX
  50.  :C8FD 5B             POP     BX
  51.  :C8FE 8B5E06         MOV     BX,[BP+06]
  52.  :C901 D1E3           SHL     BX,1
  53.  :C903 39872266       CMP     [BX+6622],AX  <- right answer?
  54.  :C907 7505           JNZ     C90E      <- no, beggar_off
  55.  :C909 B80100         MOV     AX,0001   <- yes, AX=1
  56.  :C90C EB02           JMP     C910
  57.  :C90E 2BC0           SUB     AX,AX     <- beggar_off with AX=0
  58.  :C910 8BE5           MOV     SP,BP
  59.  :C912 5D             POP     BP
  60.  :C913 CB             RETF              <- back to main
  61.  
  62. Here follow 5 questions, please answer all of them:
  63. 1)   Where in memory (in which locations) are stored the "right"
  64.      passnumbers? Where in memory is the SEGMENT of this
  65.      locations stored? How does the scheme get the OFFSET?
  66. 2)   Would setting NOPs instructions at :C965 and :C971 crack?
  67.      Would it be a good idea?
  68. 3)   Would changing :C907 to JZ crack? Would it be a good idea?
  69. 4)   Would changing :C907 to JNZ C909 crack? Would it be a good
  70.      idea?
  71. 5)   Write down (and try) at least 7 OTHER different patches to
  72.      crack this scheme in spades (without using any NOP!).
  73. Uff! By now you should be able to do the above 5 exercises in
  74. less than 15 minutes WITHOUT USING THE DEBUGGER! Just look at the
  75. data above and find the right answers feeling them... (you 'll
  76. now which one are the right one checking with your debugger...
  77. score as many points as you like for each correct answer and sip
  78. a good Martini-Wodka... do you know that the sequence should
  79. ALWAYS be 1) Ice cubes 2) Martini Dry 3) Wodka Moskovskaja 4)
  80. olive 5) lemon 6) Schweppes Indian tonic?
  81.  
  82. Let's now come to the subject of this lesson:
  83. -----> [Xoring] (Simple encryption methods)
  84.      One easy way to encrypt data is the XOR method. XOR is a bit
  85. manipulation instruction that can be used in order to cipher and
  86. decipher data with the same key:
  87.  Byte to encrypt                   key            result
  88.      FF                  XOR       A1               5E
  89.      5E                  XOR       A1               FF
  90. As you can see XOR offers a very easy way to encrypt or to
  91. decrypt data, for instance using the following routine:
  92.  encrypt_decrypt:
  93.      mov  bx, offset_where_encryption/decryption_starts
  94.  xor_loop:
  95.      mov  ah, [bx]            <-   get current byte
  96.      xor  ah, encrypt_value   <-   engage/disengage xor
  97.      mov [bx], ah             <-   back where you got it
  98.      inc  bx                  <-   ahead one byte
  99.      cmp  bx, offset_start_+_size  <- are we done?
  100.      jle  xor_loop            <-   no, then next cycle
  101.      ret                      <-   back where we came from
  102.  
  103. The encrypt_value can be always the same (fixed) or chosen at
  104. random, for instance using INT_21, service 2Ch (get current time)
  105. and choosing as encrypt_value the value reported in DL (but
  106. remembering to discard the eventual value 0, coz otherwise it
  107. would not xor anything at all!)
  108.  random_value:
  109.      mov  ah,2Ch
  110.      int  21h
  111.      cmp  dl,0
  112.      je   random_value
  113.      mov  encrypt_value,dl
  114.      The problem with XORing (and with many other encryption
  115. methods), is that the part of the code that calls the encryption
  116. routine cannot be itself encrypted. You'll somewhere have, "in
  117. clear" the encryption key.
  118.  
  119.      The protectionist do at times their best to hide the
  120. decrypting routine, here are some common methods:
  121.  
  122. -----> JUNK FILLING, SLIDING KEYS AND MUTATING DECRYPTORS
  123.   These are the more common protection method for the small
  124. decryption part of the program code. This methods, originally
  125. devised to fool signature virus scanners, have been pinched from
  126. the polymorphic virus engines of our fellows viriwriters, and are
  127. still in use for many simple decryption protection schemes. For
  128. parts of the following many thanks go to the [Black Baron], it's
  129. a real pity that so many potential good crackers dedicate so much
  130. time to useless (and pretty repetitive) virus writing instead of
  131. helping in our work. This said, virus studying is VERY important
  132. for crackers coz the code of the viri is
  133. *    ULTRAPROTECTED
  134. *    TIGHT AND EFFECTIVE
  135. *    CLOAKED AND CONCEALED.
  136.  
  137. Let's show as example of the abovementioned protection tactics
  138. the following ultra-simple decryptor:
  139.           MOV      SI,jumbled_data     ;Point to the jumbled data
  140.           MOV      CX,10               ;Ten bytes to decrypt
  141. mn_loop:  XOR      BYTE PTR [SI],44    ;XOR (un_scramble!) a byte
  142.           INC      SI                  ;Next byte
  143.           LOOP     mn_loop             ;Loop the 9 other bytes
  144.  
  145. This small program will XOR the ten bytes at the location pointed
  146. to by SI with the value 44.  Providing the ten bytes were XORed
  147. with 44 prior to running this decryptor the ten bytes will be
  148. restored to their original state.
  149. In this very simple case the "key" is the value 44. But there are
  150. several tricks involving keys, the simplest one being the use of
  151. a "sliding" key: a key that will be increased, or decreased, or
  152. multiplied, or bit-shifted, or whatever, at every pass of the
  153. loop.
  154.  
  155. A possible protection can also create a true "Polymorph"
  156. decryptor, a whole decryptor ROUTINE that looks completely
  157. different on each generation. The trick is to pepper totally
  158. random amounts of totally random instructions, including JUMPS
  159. and CALLS, that DO NOT AFFECT the registers that are used for the
  160. decryption. Also this kind of protection oft uses a different
  161. main decryptor (possibly from a selection of pre-coded ones) and
  162. oft alters on each generation also all the registers that the
  163. decryptor uses, invariably making sure that the JUNK code that
  164. it generates doesn't destroy any of the registers used by the
  165. real decryptor!  So, with these rules in mind, here is our simple
  166. decryptor again:
  167.  
  168.          MOV      DX,10              ;Real part of the decryptor!
  169.          MOV      SI,1234            ;junk
  170.          AND      AX,[SI+1234]       ;junk
  171.          CLD                         ;junk
  172.          MOV      DI,jumbled_data    ;Real part of the decryptor!
  173.          TEST     [SI+1234],BL       ;junk
  174.          OR       AL,CL              ;junk
  175. mn_loop: ADD      SI,SI              ;junk instr, but real loop!
  176.          XOR      AX,1234            ;junk
  177.          XOR      BYTE PTR [DI],44   ;Real part of the decryptor!
  178.          SUB      SI,123             ;junk
  179.          INC      DI                 ;Real part of the decryptor!
  180.          TEST     DX,1234            ;junk
  181.          AND      AL,[BP+1234]       ;junk
  182.          DEC      DX                 ;Real part of the decryptor!
  183.          NOP                         ;junk
  184.          XOR      AX,DX              ;junk
  185.          SBB      AX,[SI+1234]       ;junk
  186.          AND      DX,DX              ;Real part of the decryptor!
  187.          JNZ      mn_loop            ;Real part of the decryptor!
  188.  
  189. As you should be able to see, quite a mess! But still executable
  190. code. It is essential that any junk code generated by the
  191. Polymorph protection is executable, as it is going to be peppered
  192. throughout the decryptor. Note, in this example, that some of the
  193. junk instructions use registers that are actually used in the
  194. decryptor! This is fine, providing the values in these
  195. registers aren't destroyed. Also note, that now we have random
  196. registers and random instructions on each generation. So, a
  197. Polymorph protection Engine can be summed up into three major
  198. parts:
  199.   1 .. The random number generator.
  200.   2 .. The junk code generator.
  201.   3 .. The decryptor generator.
  202. There are other discrete parts but these three are the ones where
  203. most of the work goes on!
  204.  
  205. How does it all work?  Well a good protection would
  206. *    choose a random selection of registers to use for the
  207. decryptor and leave the remaining registers as "junk" registers
  208. for the junk code generator.
  209. *    choose one of the compressed pre-coded decryptors.
  210. *    go into a loop generating the real decryptor, peppered with
  211. junk code.
  212. From the protectionist's point of view, the advantages of this
  213. kind of method are mainly:
  214. *    the casual cracker will have to sweat to find the decryptor.
  215. *    the casual cracker will not be able to prepare a "patch" for
  216. the lamers, unless he locates and patches the generators, (that
  217. may be compressed) coz otherwise the decryptor will vary every
  218. time.
  219.  
  220. To defeat this kind of protection you need a little "zen" feeling
  221. and a moderate knowledge of assembler language... some of the
  222. junk instructions "feel" quite singular when you look at them
  223. (->see lesson B). Besides, you (now) know what may be going on
  224. and memory breakpoints will immediately trigger on decryption...
  225. the road is open and the rest is easy (->see lessons 3-5).
  226.  
  227. -----> Starting point number magic
  228. For example, say the encrypted code started at address 10h, the
  229. following could be used to index this address:
  230.  MOV   SI,10h         ;Start address
  231.  MOV   AL,[SI]        ;Index from initial address
  232. But sometimes you'll instead find something like the following,
  233. again based on the encrypted code starting at address 10h:
  234.  
  235.  MOV   DI,0BFAAh      ;Indirect start address
  236.  MOV   AL,[DI+4066h)  ;4066h + 0BFAAh = 10010h (and FFFF = 10h)!!
  237. The possible combinations are obviously infinite.
  238.  
  239. [BIG KEYS] (Complicated encryption methods)
  240.      Prime number factoring is the encryption used to protect
  241. sensible data and very expensive applications. Obviously for few
  242. digit keys the decoding is much easier than for, say, 129 or 250
  243. digit keys. Nevertheless you can crack those huge encryption too,
  244. using distributed processing of quadratic sieve equations (which
  245. is far superior for cracking purpose to the sequential processing
  246. methods) in order to break the key into prime numbers. To teach
  247. you how to do this sort of "high" cracking is a little outside
  248. the scope of my tutorial: you'll have to write a specific short
  249. dedicated program, linking together more or less half a thousand
  250. PC for a couple of hours, for a 250 bit key, this kind of things
  251. have been done quite often on Internet, were you can also find
  252. many sites that do untangle the mysteries (and vagaries) of such
  253. techniques.
  254.   As References I would advocate the works of Lai Xueejia, those
  255. swiss guys can crack *everything*. Begin with the following:
  256. Xuejia Lai, James Massey, Sean Murphy, "Markov Ciphers and
  257.      Differential Cryptanalysis", Advances in Cryptology,
  258.      Eurocrypt 1991.
  259. Xuejia Lai, "On the Design and Security of Block Ciphers",
  260.      Institute for Signal and Information Processing,
  261.      ETH-Zentrum, Zurich, Switzerland, 1992
  262. Factoring and primality testing is obviously very important for
  263. this kind of crack. The most comprehensive work I know of is:
  264. (300 pages with lengthy bibliography!)
  265.     W. Bosma & M. van der Hulst
  266.     Primality Testing with Cyclotomy
  267.     Thesis, University of Amsterdam Press.
  268. A very good old book you can incorporate in your probes to build
  269. very effective crack programs (not only for BBS accesses :=) is
  270. *the* "pomerance" catalog:
  271. Pomerance, Selfridge, & Wagstaff Jr.
  272.     The pseudoprimes to 25*10^9
  273.     Math. Comp. Vol 35 1980 pp. 1003-1026
  274.  
  275. Anyway... make a good search with Lykos, and visit the relevant
  276. sites... if encryption really interests you, you'll be back in
  277. two or three (or thirty) years and you'll resume cracking with
  278. deeper erudite knowledge.
  279. [PATENTED PROTECTION SYSTEMS]
  280.   The study of the patented enciphering methods is also *quite*
  281. interesting for our aims :=) Here are some interesting patents,
  282. if you want to walk these paths get the complete texts:
  283.      [BEST]    USPat 4168396 to Best discloses a microprocessor
  284. for executing enciphered programs. Computer programs which have
  285. been enciphered during manufacture to deter the execution of the
  286. programs in unauthorized computers, must be decrypted before
  287. execution. The disclosed microprocessor deciphers and executes
  288. an enciphered program one instruction at a time, instead of on
  289. a continuous basis, through a combination of substitutions,
  290. transpositions, and exclusive OR additions, in which the address
  291. of each instruction is combined with the instruction. Each unit
  292. may use a unique set of substitutions so that a program which can
  293. be executed on one microprocessor cannot be run on any other
  294. microprocessor. Further, Best cannot accommodate a mixture of
  295. encrypted and plain text programs.
  296.      [JOHNSTONE]    USPat 4120030 to Johnstone describes a
  297. computer in which the data portion of instructions are scrambled
  298. and in which the data is of necessity stored in a separate
  299. memory. There is no disclosure of operating with instructions
  300. which are completely encrypted with both the operation code and
  301. the data address portion being unreadable without a corresponding
  302. key kernel.
  303.      [TWINPROGS]    USPat 4183085 describes a technique for
  304. protecting software by providing two separate program storages.
  305. The first program storage is a secure storage and the second
  306. program storage is a free storage. Security logic is provided to
  307. check whether an output instruction has originated in the secure
  308. store and to prevent operation of an output unit which receives
  309. output instructions from the free storage. This makes it
  310. difficult to produce information by loading a program into free
  311. storage.
  312.      [AUTHENTICATOR]     USPat 3996449 entitled "Operating System
  313. Authenticator," discloses a technique for authenticating the
  314. validity of a plain text program read into a computer, by
  315. exclusive OR'ing the plain text of the program with a key to
  316. generate a code word which must be a standard recognizable code
  317. word which is successfully compared with a standard corresponding
  318. code word stored in the computer. If there is a successful
  319. compare, then the plain text program is considered to be
  320. authenticated and is allowed to run, otherwise the program
  321. is not allowed to run.
  322.  
  323. ELEMENTS OF [PGP] CRACKING
  324. In order to try to crack PGP, you need to understand how these
  325. public/private keys systems work. Cracking PGP seems extremely
  326. difficult, though... I have a special dedicated "attack" computer
  327. that runs 24 hours on 24 only to this aim and yet have only begun
  328. to see the light at the famous other end of the tunnel. It's
  329. hard, but good crackers never resign! We'll see... I publish here
  330. the following only in the hope that somebody else will one day
  331. be able to help...
  332. In the public key cryptosystems, like PGP, each user has an
  333. associated encryption key E=(e,n) and decryption key D=(d,n),
  334. wherein the encryption keys for all users are available in a
  335. public file, while the decryption keys for the users are only
  336. known to the respective users. In order to maintain a high level
  337. of security a user's decoding key is not determinable in a
  338. practical manner from that user's encoding (public) key. Normally
  339. in such systems, since
  340.      e.multidot.d.ident.1 (mod(1 cm((p-1),(q-1)))),
  341. (where "1 cm((p-1),(q-1))" is the least common multiple of the
  342. numbers p-1 and q-1)
  343.  
  344. d can be determined from e provided p and q are also known.
  345. Accordingly, the security of the system is dependent upon the
  346. ability to determine p and q which are the prime factors of n.
  347. By selecting p and q to be large primes, the resultant composite
  348. number n is also large, and correspondingly difficult to factor.
  349. For example, using known computer-implemented factorization
  350. methods, on the order of 10.sup.9 years is required to factor a
  351. 200 digit long number. Thus, as a practical matter, although a
  352. user's encryption key E=(e,n) is public, the prime factors p and
  353. q of n are effectively hidden from anyone due to the enormous
  354. difficulty in factoring n. These aspects are described more fully
  355. in the abundant publications on digital signatures and Public-Key
  356. Cryptosystems. Most public/private systems relies on a message-
  357. digest algorithm.
  358.   A message-digest algorithm maps a message of arbitrary length
  359. to a "digest" of fixed length, and has three properties:
  360. Computing the digest is easy, finding a message with a given
  361. digest "inversion" is hard, and finding two messages with the
  362. same digest "collision" is also hard. Message-digest algorithms
  363. have many applications, not only digital signatures and message
  364. authentication. RSA Data Security's MD5 message-digest algorithm,
  365. developed by Ron Rivest, maps a message to a 128-bit message
  366. digest. Computing the digest of a one-megabyte message takes as
  367. little as a second.  While no message-digest algorithm can yet
  368. be secure, MD5 is believed to be at least as good as any other
  369. that maps to a 128-bit digest.
  370.   As a final gift, I'll tell you that PGP relies on MD5 for a
  371. secure one-way hash function. For PGP this is troublesome, to say
  372. the least, coz an approximate relation exists between any four
  373. consecutive additive constants. This means that one of the design
  374. principles behind MD4 (and MD5), namely to design a collision
  375. resistant function, is not satisfied. You can construct two
  376. chaining variables (that only differ in the most significant bit
  377. of every word) and a single message block that yield the same
  378. hashcode. The attack takes a few minutes on a PC. From here you
  379. should start, as I did.
  380.  
  381. [DOS 4GW] cracking - This is only a very provisory part of this
  382. tutorial. DOS 4GW cracking will be much better described as soon
  383. as [Lost soul] sends his stuff, if he ever does. For (parts of)
  384. the following I thank [The Interrupt].
  385.      Most applications of every OS, and also of DOS 4GW, are
  386. written in C language, coz as you'll have already learned or,
  387. either, you'll learn, only C allows you to get the "guts" of a
  388. program, almost approaching the effectiveness of assembler
  389. language.
  390.      C is therefore the LANGUAGE OF CHOICE for crackers, when you
  391. prepare your tools and do not directly use assembler routines.
  392. Besides... you'll be able to find VERY GOOD books about C for
  393. next to nothing in the second hand bookshops. All the lusers are
  394. throwing money away in spades buying huge, coloured and
  395. absolutely useless books on unproductive "bloated" languages like
  396. Visual basic, C++ and Delphy. Good C new books are now rare
  397. (books on assembler language have always been) and can be found
  398. almost exclusively on the second hand market. Find them, buy
  399. them, read them, use them for your/our aims. You can find a lot
  400. of C tutorials and of C material on the Web, by all means DO IT!
  401. Be a conscientious cracker... learn C! It's cheap, lean, mean and
  402. very productive (and creative) :=)
  403.      Back to the point: most stuff is written in C and therefore
  404. you need to find the "main" sub-routine inside the asm. With
  405. DOS/4GW programs, search the exe file for "90 90 90 90", almost
  406. always it'll be at the start of the compiled code. Now search for
  407. an INT_21 executed with 4C in AH, the exec to dos code (if you
  408. cannot "BPINT 21 AH=4C" with your tool, then search for the
  409. sequence "b4 4c cd 21". This is the equivalent to [mov AH,4C &
  410. int 21]: it's the most direct call, but as you'll have already
  411. learned, there are half a dozen ways to put 4C in AX, try them
  412. all in the order of their frequency).
  413.      A few bytes above the INT_21 service 4C, you'll find the
  414. call to the "main" subroutine: "E8 xx xx". Now place a "CC" byte
  415. a few bytes above the call in the exe and run the exe under a
  416. debugger. When the computer tries to execute the instruction
  417. you'll be throw back in the debugger coz the "CC" byte acts as
  418. INT_01 instruction. Then proceed as usual.
  419.  
  420. [THE "STEGONATED" PASSWORD HIDEOUT]
  421.   A last, very nice trick should be explained to every wannabe
  422. cracker, coz it would be embarrassing to search for passwords or
  423. protection routines that (apparently) are not there. They may be
  424. hidden INSIDE a picture (or a *.waw file for that matter). This
  425. is steganography, a method of disguising messages within other
  426. media.
  427.   Depending on how many shades of grey or hues of colour you want
  428. to have, a pixel can be expressed using 8. 16, 32 or even more
  429. bits. If the least significant bit is changed. the shade of the
  430. pixel is altered only one-256th, one-65,OOOth or even less. No
  431. human eye could tell the difference.
  432.   What the protectionist does, is hijack the least significant
  433. bit in each pixel of a picture. It uses that bit to store one bit
  434. of a protection, or of a password (or of a file, or of a secret
  435. message). Because digitized pictures have lots of pixels, it's
  436. possible to store lots of data in a single picture. A simple
  437. algorithm will transfer them to the relevant parts of the program
  438. when it needs be, and there we'll intercept them. You'll need to
  439. learn very well the zen-cracking techniques to smell this kind
  440. of stuff though (-> see lesson B).
  441.  
  442. Well, that's it for this lesson, reader. Not all lessons of my
  443. tutorial are on the Web.
  444.  
  445.      You 'll obtain the OTHER missing lessons IF AND ONLY IF you
  446. mail me back (via anon.penet.fi) with some tricks of the trade
  447. I may not know that YOU discovered. Mostly I'll actually know
  448. them already, but if they are really new you'll be given full
  449. credit, and even if they are not, should I judge that you
  450. "rediscovered" them with your work, or that you actually did good
  451. work on them, I'll send you the remaining lessons nevertheless.
  452. Your suggestions and critics on the whole crap I wrote are also
  453. welcomed.
  454.  
  455.                                 E-mail +ORC
  456.  
  457.                        an526164@anon.penet.fi (+ORC)
  458.